package com.example.app.components


import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.height
import androidx.compose.material.Button
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.SecureFlagPolicy

@Composable
fun DropdownMenuSample() {

    var show by remember {
        mutableStateOf(false)
    }

    Column() {
        Button(onClick = {
            show = true
        }) {
            Text(text = "Button")
        }
        // expanded菜单是否展开
        // onDismissRequest点击菜单以外的部分触发
        // offset弹窗偏移量
        DropdownMenu(expanded = show, offset = DpOffset(20.dp, 50.dp), onDismissRequest = { show = false }) {
            DropdownMenuItem(onClick = {
                show = false
            }) {
                Text(text = "Menu 0")
            }
            DropdownMenuItem(onClick = {
                show = false
            }) {
                Text(text = "Menu 1")
            }
            DropdownMenuItem(onClick = {
                show = false
            }) {
                Text(text = "Menu 2")
            }
        }
    }
}

@Preview(
    showSystemUi = true
)
@Composable
fun DropdownMenuSamplePreview() {
    DropdownMenuSample()
}

